package com.mengma.ec.service.impl.portal;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mengma.ec.commons.ServerResponse;
import com.mengma.ec.dao.ShippingMapper;
import com.mengma.ec.entity.Product;
import com.mengma.ec.entity.Shipping;
import com.mengma.ec.service.portal.IShippingService;
import com.mengma.ec.vo.ProductListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
 * @Auther: xixi
 * @Date: 2018/9/25 09:29
 * @Description:
 */
@Service("iShippingService")
public class ShippingServiceImpl implements IShippingService {

    @Autowired
    public ShippingMapper shippingMapper;
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
    //增
    @Override
    public ServerResponse add(Integer id, Shipping shipping) {
        shipping.setUserId(id);

        int insert = shippingMapper.insert(shipping);
        if(insert>0){
            return ServerResponse.createBySuccess("新增成功！",shipping.getId()+"");
        }
        return ServerResponse.createByErrorMessage("新增失败！");
      }

      //删
    @Override
    public ServerResponse delete(Integer shippingId) {
        int i = shippingMapper.deleteByPrimaryKey(shippingId);
        if (i>0) {
            return ServerResponse.createBySuccess("删除成功！");

        }
        return ServerResponse.createByErrorMessage("删除失败！");
    }

    @Override
    public ServerResponse findListData(Integer pageNum, Integer pageSize, Integer id) {
        PageHelper.startPage(pageNum,pageSize);
        //获取原始数据源
        List<Product> list = shippingMapper.findListData(id);

        PageInfo pageInfo = new PageInfo(list);

        return ServerResponse.createBySuccess(pageInfo);
    }

    @Override
    public ServerResponse updata(Integer id, Shipping shipping) {
        shipping.setUserId(id);

        int insert = shippingMapper.updateByPrimaryKey(shipping);
        if(insert>0){
            return ServerResponse.createBySuccess("修改成功");
        }
        return ServerResponse.createByErrorMessage("修改失败！");
    }

    @Override
    public ServerResponse select(Integer shippingId) {
        Shipping shipping = shippingMapper.selectByPrimaryKey(shippingId);
        if(shipping == null){
            return ServerResponse.createByErrorMessage("查询失败");
        }
        return ServerResponse.createBySuccess("查询成功！",shipping);
    }


}
